package chuishop.yiqimaicai.service.Impl;

import chuishop.yiqimaicai.mapper.EmployeeMapper;
import chuishop.yiqimaicai.pojo.Employee;
import chuishop.yiqimaicai.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public List<Employee> findAllEmployee() {
        return employeeMapper.findAllEmployee();
    }

    @Override
    public boolean addEmployee(Employee employee) {
        if(employeeMapper.addEmployee(employee)>0){
            return true;
        }
         return false;
    }

    @Override
    public boolean deleteEmployee(String[] ids) {
        if(employeeMapper.deleteEmployee(ids)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateEmployee(Employee employee) {
//        System.out.println(  employee.getName()+','
//                            +employee.getPassword()+','
//                            +employee.getEmail()+','
//                            +employee.getIdentity()+','
//                            +employee.getId()+'.');
        if(employeeMapper.updateEmployee(employee)>0){
            return true;
        }
        return false;
    }

    @Override
    public List<Employee> searchEmployeeByname(String name) {
        System.out.println("serviceImpl的searchEmployeeByname的name1为:"+name);
        return employeeMapper.searchEmployeeByname(name);
    }

    @Override
    public boolean loginEmployee(String idpassword) {
        if(employeeMapper.loginEmployee(idpassword)>0){
            return true;
        }
        return false;
    }

    @Override
    public Employee login(Integer id, String password) {
        //调用根据员工id查询员工对象的方法

        Employee employee=employeeMapper.findEmployeeById(id);
        if(employee!=null){
            return employee;
        }
        return null;
    }

    @Override
    public List<Employee> findEmplyeeBylimits(int limits) {

        return employeeMapper.findEmplyeeBylimits(limits);
    }


}
